﻿function compareUser(obj) {
	if (refreshWin('compareUser')) return;
	obj = defaultx(obj, 'usernameB');

	var userA = new Ext.form.TextField({
				fieldLabel : '用户A',
				anchor : '100%',
				minLength : 5,
				maxLength : 20,
				allowBlank : false,
				value : obj.usernameA || (sys.guest ? null : sys.user.username)
			});
	var userB = new Ext.form.TextField({
				fieldLabel : '用户B',
				anchor : '95%',
				minLength : 5,
				maxLength : 20,
				allowBlank : false,
				value : obj.usernameB
			});
	var btnMe = new Ext.Button({
				text : '我',
				anchor : '67%',
				handler : function() {
					if (sys.guest) return;
					userA.setValue(sys.user.username);
				}
			});
	var btnSubmit = new Ext.Button({
				text : '比较',
				iconCls : 'ok-icon',
				handler : oncompare
			});
	var toolbar = new Ext.Toolbar({
				items : [new Ext.Toolbar.Fill(), btnSubmit]
			})

	var form = new Ext.form.FormPanel({
				frame : true,
				labelAlign : 'right',
				labelWidth : 50,
				items : [{
							layout : 'column',
							items : [{
										layout : 'form',
										columnWidth : .85,
										style : 'padding-right:5px',
										items : userA
									}, {
										layout : 'form',
										columnWidth : .15,
										items : btnMe
									}]
						}, userB]
			});
	var win = new Ext.Window({
				id : 'compareUser',
				title : '比较',
				iconCls : 'compare-icon',
				manager : ui.windows,
				width : 300,
				minWidth : 200,
				items : form,
				bbar : toolbar
			});
	win.show();

	function oncompare() {
		if (!form.getForm().isValid()) {
			alertx('请正确输入信息！');
			return;
		}
		var usernameA = userA.getValue();
		var usernameB = userB.getValue();
		showCompareUser(usernameA, usernameB);
		win.close();
	}
}